package model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Machine {
	int id;
	int neighborhood;
	int location;
	HashMap<String, Integer> capacities;
	HashMap<String, Integer> safetyCapacities;
	List<String> processes;
	List<Integer> machineMoveCosts;
	List<Integer> moveableProcesses;

	public Machine() {
		capacities = new HashMap<String, Integer>();
		safetyCapacities = new HashMap<String, Integer>();
		processes = new ArrayList<String>();
		machineMoveCosts = new ArrayList<Integer>();
		moveableProcesses = new ArrayList<Integer>();
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public void setNeighborhood(int n) {
		this.neighborhood = n;
	}

	public void setLocation(int loc) {
		this.location = loc;
	}

	public void addCapacity(String s, int value) {
		capacities.put(s, value);
	}

	public void addSafetyCapacity(String s, int value) {
		safetyCapacities.put(s, value);
	}

	public void addMachineMoveCost(int value) {
		machineMoveCosts.add(value);
	}

	public int getCapacityFor(String r_i_s) {
		return capacities.get(r_i_s);
	}

	public int getSafetyCapacityFor(String r_i_s) {
		return safetyCapacities.get(r_i_s);
	}

	public int getMachineMoveCost(int mdest) {
		return machineMoveCosts.get(mdest);
	}

	public int getLocation() {
		return location;
	}

	public int getNeighborhood() {
		return neighborhood;
	}

	public String capacityString() {
		StringBuilder sb = new StringBuilder();
		for (String key : capacities.keySet()) {
			sb.append(String.format("%s->%,d\t", key, capacities.get(key)));
		}
		return sb.toString();
	}

	public void addMoveableProcess(Integer p) {
		if (!moveableProcesses.contains(p))
			moveableProcesses.add(p);
	}

	public void clearMoveableProcesses() {
		moveableProcesses.clear();
	}

	public List<Integer> getMoveableProcesses() {
		return moveableProcesses;
	}

	public void setMoveableProcesses(List<Integer> moveableProcesses) {
		this.moveableProcesses = moveableProcesses;
	}

	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(String.format("ID=%s NEIGHBORHOOD=%s LOCATION=%s\n", id,
				neighborhood, location));
		sb.append("Capacities: ");
		for (String key : capacities.keySet()) {
			sb.append(String.format("%s->%,d\t", key, capacities.get(key)));
		}
		sb.append("\n");
		sb.append("Safety Cap: ");
		for (String key : safetyCapacities.keySet()) {
			sb.append(String.format("%s->%,d\t", key, safetyCapacities.get(key)));
		}
		sb.append("\n");
		sb.append("MachineMoveCosts\n");
		int c = 0;
		for (Integer mmc : machineMoveCosts) {
			sb.append(String.format("%d->%d, ", c, mmc));
			c++;
		}
		sb.append("\n");
		return sb.toString();
	}
}
